package org.tigris.atlas.examples.service.impl;

import java.lang.Boolean;
import java.lang.Integer;
import java.lang.Long;
import java.lang.String;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date;

import org.tigris.atlas.messages.Message;
import org.tigris.atlas.messages.MessageFactory;
import org.tigris.atlas.messages.Messages;
import org.tigris.atlas.messages.Severity;
import org.tigris.atlas.service.BigDecimalServiceResponse;
import org.tigris.atlas.service.BooleanServiceResponse;
import org.tigris.atlas.service.DateServiceResponse;
import org.tigris.atlas.service.IntegerServiceResponse;
import org.tigris.atlas.service.LongServiceResponse;
import org.tigris.atlas.service.ServiceResponse;
import org.tigris.atlas.service.StringServiceResponse;
import org.tigris.atlas.service.TimestampServiceResponse;
import org.tigris.atlas.service.VoidServiceResponse;


/**
 * Service implementation class for the PrimitiveReturnTypeExample service
 * @see org.tigris.atlas.examples.service.PrimitiveReturnTypeExampleService
 */
public class PrimitiveReturnTypeExampleServiceImpl extends PrimitiveReturnTypeExampleServiceBaseImpl {

	/**
	 * Execute the ReturnBoolean service
	 * @see org.tigris.atlas.examples.service.PrimitiveReturnTypeExampleService#ReturnBoolean()
	 */
	protected void returnBooleanImpl(Boolean isReturnValueNull, Boolean areMessagesNull, Boolean primitive, BooleanServiceResponse response) {
		boolean shouldAddReturnValue = (isReturnValueNull != null) ? isReturnValueNull.booleanValue() : false;
		if (shouldAddReturnValue) {
			response.setBoolean(Boolean.FALSE);
		}
		
		addMessages(response, areMessagesNull);
	}


	/**
	 * Execute the ReturnDate service
	 * @see org.tigris.atlas.examples.service.PrimitiveReturnTypeExampleService#ReturnDate()
	 */
	protected void returnDateImpl(Boolean isReturnValueNull, Boolean areMessagesNull, Date primitive, DateServiceResponse response) {
		boolean shouldAddReturnValue = (isReturnValueNull != null) ? isReturnValueNull.booleanValue() : false;
		if (shouldAddReturnValue) {
			response.setDate(new Date());
		}
		addMessages(response, areMessagesNull);
	}


	/**
	 * Execute the ReturnInteger service
	 * @see org.tigris.atlas.examples.service.PrimitiveReturnTypeExampleService#ReturnInteger()
	 */
	protected void returnIntegerImpl(Boolean isReturnValueNull, Boolean areMessagesNull, Integer primitive, IntegerServiceResponse response) {
		boolean shouldAddReturnValue = (isReturnValueNull != null) ? isReturnValueNull.booleanValue() : false;
		if (shouldAddReturnValue) {
			response.setInteger(new Integer( Integer.MAX_VALUE ));
		}
		addMessages(response, areMessagesNull);
	}


	/**
	 * Execute the ReturnLong service
	 * @see org.tigris.atlas.examples.service.PrimitiveReturnTypeExampleService#ReturnLong()
	 */
	protected void returnLongImpl(Boolean isReturnValueNull, Boolean areMessagesNull, Long primitive, LongServiceResponse response) {
		boolean shouldAddReturnValue = (isReturnValueNull != null) ? isReturnValueNull.booleanValue() : false;
		if (shouldAddReturnValue) {
			response.setLong(new Long(Long.MIN_VALUE));
		}
		addMessages(response, areMessagesNull);
	}


	/**
	 * Execute the ReturnVoid service
	 * @see org.tigris.atlas.examples.service.PrimitiveReturnTypeExampleService#ReturnVoid()
	 */
	protected void returnVoidImpl(Boolean areMessagesNull, VoidServiceResponse response) {
		addMessages(response, areMessagesNull);
	}


	/**
	 * Execute the ReturnString service
	 * @see org.tigris.atlas.examples.service.PrimitiveReturnTypeExampleService#ReturnString()
	 */
	protected void returnStringImpl(Boolean isReturnValueNull, Boolean areMessagesNull, String primitive, StringServiceResponse response) {
		boolean shouldAddReturnValue = (isReturnValueNull != null) ? isReturnValueNull.booleanValue() : false;
		if (shouldAddReturnValue) {
			response.setString("This string is set");
		}
		addMessages(response, areMessagesNull);
	}


	/**
	 * Execute the ReturnBigDecimal service
	 * @see org.tigris.atlas.examples.service.PrimitiveReturnTypeExampleService#ReturnBigDecimal()
	 */
	protected void returnBigDecimalImpl(Boolean isReturnValueNull, Boolean areMessagesNull, BigDecimal primitive, BigDecimalServiceResponse response) {
		boolean shouldAddReturnValue = (isReturnValueNull != null) ? isReturnValueNull.booleanValue() : false;
		if (shouldAddReturnValue) {
			response.setBigDecimal(BigDecimal.TEN);
		}
		addMessages(response, areMessagesNull);
	}


	/**
	 * Execute the ReturnTimestamp service
	 * @see org.tigris.atlas.examples.service.PrimitiveReturnTypeExampleService#ReturnTimestamp()
	 */
	protected void returnTimestampImpl(Boolean isReturnValueNull, Boolean areMessagesNull, Timestamp primitive, TimestampServiceResponse response) {
		boolean shouldAddReturnValue = (isReturnValueNull != null) ? isReturnValueNull.booleanValue() : false;
		if (shouldAddReturnValue) {
			response.setTimestamp(new Timestamp(System.currentTimeMillis()));
		}
		addMessages(response, areMessagesNull);
	}
	
	private void addMessages(ServiceResponse response, Boolean areMessagesNull) {
		boolean shouldAddMessages = (areMessagesNull != null) ? areMessagesNull.booleanValue() : false;
		if (shouldAddMessages) {
			Messages m = response.getMessages();
			Message message = MessageFactory.createMessage();
			message.addProperty("foo");
			message.addInsert("bar");
			message.setKey("primitiveReturnTypeTestKey");
			message.setSeverity(Severity.getSeverity(Severity.ERROR));
			m.addMessage(message);
		}
	}

}